package org.pi.common.matrix.range

class IntRangeImpl(override val start: Int, override val step: Int, override val end: Int, private var valsSpecified: Int) extends IntRange {
	if (step==0) throw new Error("step must not be zero")
	if (valsSpecified<1 || valsSpecified>3) throw new Error("valsSpecified must be between 1 and 2")
	
	override def toIntMatrixForGivenStartEndIndices(startIndex: Int, endIndex: Int) : org.pi.common.matrix.IntMatrix = {
		if (end<startIndex) new IntRangeImpl(start, step, endIndex+(end-startIndex),valsSpecified).toIntMatrix
		else this.toIntMatrix
	}

	def this(startParam: Int) = this(startParam,1,startParam, 1)
	def this(startParam: Int, endParam: Int) = this(startParam,1,endParam, 2)
	def this(startParam: Int, stepParam: Int, endParam: Int) = this(startParam,stepParam,endParam,3)
	def ~(x:Int): IntRangeImpl = {
		if (valsSpecified==1) new IntRangeImpl(start,x)
		else if (valsSpecified==2) new IntRangeImpl(start,end,x)
		else throw new Error("cannot add more info to fully specified range (e.g. 1:2:10:3 is not allowed)")
	}
}
